﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using WPFEdit.Util;

namespace WPFEdit.Document.Factory
{
    public abstract class InterfaceFactory <TInterface, TKey, TValue, TAttribute>
    {
        protected List<Assembly> m_assemblies = new List<Assembly>();
        protected Dictionary<TKey, TValue> m_factoryInstances = new Dictionary<TKey, TValue>();

        public IList<Assembly> Assemblies
        {
            get { return m_assemblies; }
        }

        public void Init()
        {
            foreach (Assembly assembly in m_assemblies)
            {
                foreach (Tuple<Type, object[], ConstructorInfo> typeInfo in Reflection.GetSubclassesWithAttributesAndConstructor<TInterface>(assembly, typeof(TAttribute)))
                {
                    AddType(typeInfo.Item1, typeInfo.Item2, typeInfo.Item3);
                }
            }
            m_assemblies.Clear();
        }

        protected abstract void AddType(Type type, object[] attributeInstances, ConstructorInfo constructorInfo);



    }
}
